Exemple #1
0
        public IHttpActionResult Create([FromBody] Entities.Table.Sucursal entity)
        {
            try
            {
                if (entity != null)
                {
                    using (var scope = new TransactionScope())
                    {
                        var save = new Business.Table.Sucursal(entity).Save();
                        if (save.result.Success)
                        {
                            scope.Complete();

                            return(Created <Entities.Table.Sucursal>($"{Request.RequestUri}/{save.domain?.Id?.ToString()}", save.domain?.Data?.Entity));
                        }

                        return(InternalServerError());
                    }
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                var load = new Business.Table.Sucursal()
                {
                    Id = id
                }.Load();
                if (load.result.Success)
                {
                    if (load.domain != null)
                    {
                        return(Ok(load.domain?.Data?.Entity));
                    }

                    return(NotFound());
                }

                return(InternalServerError());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #3
0
        public IHttpActionResult Update(int id, [FromBody] Entities.Table.Sucursal entity)
        {
            try
            {
                if (entity != null)
                {
                    var load = new Business.Table.Sucursal()
                    {
                        Id = id
                    }.Load();
                    if (load.result.Success)
                    {
                        if (load.domain != null)
                        {
                            load.domain.Entity = entity;

                            using (var scope = new TransactionScope())
                            {
                                var save = load.domain.Save();
                                if (save.result.Success)
                                {
                                    scope.Complete();

                                    return(Ok(save.domain?.Data?.Entity));
                                }

                                return(InternalServerError());
                            }
                        }

                        return(NotFound());
                    }

                    return(InternalServerError());
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #4
0
        public IHttpActionResult Delete(int id)
        {
            try
            {
                var load = new Business.Table.Sucursal()
                {
                    Id = id
                }.Load();
                if (load.result.Success)
                {
                    if (load.domain != null)
                    {
                        using (var scope = new TransactionScope())
                        {
                            var erase = load.domain.Erase();
                            if (erase.result.Success)
                            {
                                scope.Complete();

                                return(StatusCode(HttpStatusCode.NoContent));
                            }

                            return(InternalServerError());
                        }
                    }

                    return(NotFound());
                }

                return(InternalServerError());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }