public void Create(SectorDTO obj)
 {
     using (SqlConnection conn = new SqlConnection(DBConnection._connectionString))
     {
         throw new NotImplementedException();
     }
 }
Пример #2
0
        public async Task <IHttpActionResult> NewSector(SectorDTO newSectorDTO)
        {
            string userName = User.Identity.Name;
            User   user     = db.Users.Where(_user => _user.UserName == userName).SingleOrDefault();

            if (user == null)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Sector exist = db.Sectors.SingleOrDefault(sec => sec.SectorName == newSectorDTO.SectorName);

            if (exist != null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }


            newSectorDTO.CreateDate = DateTime.Now;
            newSectorDTO.Active     = true;

            Sector sector = Mapper.Map <SectorDTO, Sector>(newSectorDTO);

            db.Sectors.Add(sector);
            await db.SaveChangesAsync();

            return(Ok(Mapper.Map <Sector, SectorDTO>(sector)));
        }
Пример #3
0
        public bool update(SectorDTO oSector)
        {
            bool          bReturn = false;
            SqlConnection sqlCon  = DBLibrary.OpenConnection();

            try
            {
                SqlCommand sqlCmd = new SqlCommand();

                sqlCmd.Connection  = sqlCon;
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.CommandText = "sp_sector_update";
                sqlCmd.Parameters.AddWithValue("@IdSector", oSector.idSector);
                sqlCmd.Parameters.AddWithValue("@DsSector", oSector.dsSector);

                sqlCmd.ExecuteNonQuery();

                bReturn = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sqlCon.Close();
            }

            return(bReturn);
        }
        public SectorDTO Read(int key)
        {
            SectorDTO sector = new SectorDTO();

            using (SqlConnection conn = new SqlConnection(DBConnection._connectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand($"SELECT dbo.Track.Id, dbo.Sector.TramId, dbo.Sector.Location, dbo.Track.TrackNumber FROM dbo.Sector INNER JOIN dbo.Track ON dbo.Sector.Id = dbo.Track.Id INNER JOIN dbo.Tram ON dbo.Sector.Id = dbo.Tram.Id WHERE dbo.Sector.Id = @key", conn))
                {
                    cmd.Parameters.AddWithValue("@key", key);
                    using (SqlDataReader dataReader = cmd.ExecuteReader())
                    {
                        while (dataReader.Read())
                        {
                            sector.Id = dataReader.GetInt32(0);

                            if (!dataReader.IsDBNull(1))
                            {
                                sector.Tram    = new TramDTO();
                                sector.Tram.Id = dataReader.GetInt32(1);
                            }

                            sector.SectorPosition = dataReader.GetInt32(2);
                            sector.TrackNumber    = dataReader.GetInt32(3);
                        }
                    }
                }
                conn.Close();
            }
            return(sector);
        }
 public void Update(SectorDTO obj)
 {
     try
     {
         if (obj.Tram != null)
         {
             using (SqlConnection conn = new SqlConnection(DBConnection._connectionString))
             {
                 conn.Open();
                 string query = "UPDATE Sector SET TramId = @tramId WHERE Id = @sectorId";
                 using (SqlCommand cmd = new SqlCommand(query, conn))
                 {
                     cmd.Parameters.AddWithValue("@sectorId", obj.Id);
                     cmd.Parameters.AddWithValue("@tramId", obj.Tram.Id);
                     cmd.ExecuteNonQuery();
                 }
                 conn.Close();
             }
         }
         else
         {
             RemoveTram(obj);
         }
     }
     catch
     {
     }
 }
Пример #6
0
        public Sector GetSectorById(int id)
        {
            SectorDTO sector    = this._sectorDAL.GetById(id);
            User      deletedBy = this._userContainer.GetUserById(sector.DeletedBy);

            return(new Sector(sector, deletedBy));
        }
        private async Task <Notification> EditSector(SectorDTO sectorDTO, IdentityUser user)
        {
            try
            {
                var record = await _sectorCrudService.GetAsync(sectorDTO.Sector.Id);

                record.Name         = sectorDTO.Sector.Name;
                record.Code         = sectorDTO.Sector.Code;
                record.ModifiedBy   = user.Id;
                record.ModifiedDate = DateTime.Now;

                foreach (var sectorTransport in sectorDTO.SectorTransport)
                {
                    var recordST = await _sectorTransportCrudService.GetAsync(p => p.SectorId == sectorDTO.Sector.Id && p.TransportId == sectorTransport.TransportId);

                    recordST.Cost       = sectorTransport.Cost;
                    recordST.ModifiedBy = user.Id;
                    record.ModifiedDate = DateTime.Now;

                    _sectorTransportCrudService.Update(recordST);
                }

                _sectorCrudService.Update(record);

                return(new Notification("success", "Sector updated successfully."));
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(new Notification("error", "Sector update failed."));
            }
        }
 public async Task Update(SectorDTO obj)
 {
     using (_context)
     {
         _context.Update(obj);
         await _context.SaveChangesAsync();
     }
 }
Пример #9
0
 public Sector(SectorDTO sectorDTO)
 {
     this.Id        = sectorDTO.Id;
     this.Name      = sectorDTO.Name;
     this.CreatedAt = sectorDTO.CreatedAt;
     this.DeletedAt = sectorDTO.DeletedAt;
     this.DeletedBy = UserContainer.GetUserById(sectorDTO.DeletedBy);
 }
Пример #10
0
 public Sector(SectorDTO sectorDTO)
 {
     Id        = sectorDTO.Id;
     Name      = sectorDTO.Name;
     CreatedAt = sectorDTO.CreatedAt;
     DeletedAt = sectorDTO.DeletedAt;
     DeletedBy = sectorDTO.DeletedBy;
 }
 public void AddTram(SectorDTO sector, TramDTO tram)
 {
     if (sector.Tram == null)
     {
         sector.Tram = tram;
         _sectoraccess.Update(sector);
     }
 }
Пример #12
0
 public Sector(SectorDTO sectorDTO, User deletedBy)
 {
     this.Id        = sectorDTO.Id;
     this.Name      = sectorDTO.Name;
     this.CreatedAt = sectorDTO.CreatedAt;
     this.DeletedAt = sectorDTO.DeletedAt;
     this.DeletedBy = deletedBy;
 }
Пример #13
0
 public static Sector SectortoDal(SectorDTO com)
 {
     return(new Sector
     {
         SectorCode = com.SectorCode,
         SectorName = com.SectorName
     });
 }
 public SectorDTO Read(int key)
 {
     using (_context)
     {
         SectorDTO sector     = new SectorDTO();
         var       readsector = _context.Sector.FirstOrDefault(i => i.Id == key);
         return(sector = _mapper.Map <SectorDTO>(readsector));
     }
 }
 public bool CheckIfSectorIsEmpty(SectorDTO sector)
 {
     if (sector.Tram == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #16
0
        public static Sector Map(SectorDTO dto)
        {
            Sector m = new Sector();

            m.EmpresaId = dto.EmpresaId;
            if (dto.Nombre != null)
            {
                m.Nombre = dto.Nombre;
            }
            return(m);
        }
Пример #17
0
        public static SectorDTO Map(Sector s)
        {
            SectorDTO dto = new SectorDTO();

            dto.SectorId  = s.SectorId;
            dto.EmpresaId = s.EmpresaId;
            if (s.Nombre != null)
            {
                dto.Nombre = s.Nombre;
            }
            return(dto);
        }
Пример #18
0
        public async Task <IActionResult> Post([FromBody] SectorDTO sectorDTO)
        {
            var sector = await sectorService.InsertSectorAsync(sectorDTO);

            if (sector == null)
            {
                return(BadRequest());
            }
            else
            {
                return(Created($"api/sectors/{sector.Id}", sector));
            }
        }
Пример #19
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] SectorDTO sectorDTO)
        {
            var sector = await sectorService.UpdateSectorAsync(id, sectorDTO);

            if (sector == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(sector));
            }
        }
Пример #20
0
        public static List <SectorDTO> GetListSector()
        {
            string           query      = string.Format("EXEC dbo.USP_GetListSector");
            DataTable        dataTable  = DataProvider.ExcuteQuery(query);
            List <SectorDTO> ListSector = new List <SectorDTO>();

            foreach (DataRow item in dataTable.Rows)
            {
                SectorDTO Sector = new SectorDTO(item);
                ListSector.Add(Sector);
            }
            return(ListSector);
        }
 private void RemoveTram(SectorDTO sector)
 {
     using (SqlConnection conn = new SqlConnection(DBConnection._connectionString))
     {
         conn.Open();
         string query = "UPDATE Sector SET TramId = null WHERE Id = @sectorId";
         using (SqlCommand cmd = new SqlCommand(query, conn))
         {
             cmd.Parameters.AddWithValue("@sectorId", sector.Id);
             cmd.ExecuteNonQuery();
         }
         conn.Close();
     }
 }
Пример #22
0
        public async Task <IActionResult> Save(SectorDTO sectorDTO)
        {
            try
            {
                var user = _userManager.GetUserAsync(HttpContext.User).Result;
                notification = new Notification();

                _unitOfWork.BeginTransaction();

                if (sectorDTO.Sector.Id > 0)
                {
                    notification = await EditSector(sectorDTO, user);
                }
                else
                {
                    int sectorId = await _sectorCrudService.InsertAsync(new Sector
                    {
                        Name      = sectorDTO.Sector.Name,
                        Code      = sectorDTO.Sector.Code,
                        CreatedBy = user.Id
                    });

                    foreach (var sectorTransport in sectorDTO.SectorTransport)
                    {
                        await _sectorTransportCrudService.InsertAsync(new SectorTransport
                        {
                            SectorId    = sectorId,
                            TransportId = sectorTransport.TransportId,
                            Cost        = sectorTransport.Cost,
                            CreatedBy   = user.Id
                        });
                    }

                    notification.Type    = "success";
                    notification.Message = "Sector created successfully.";
                }

                _unitOfWork.Commit();

                return(Json(notification));
            }
            catch (Exception exception)
            {
                _unitOfWork.Rollback();
                notification.Type    = "error";
                notification.Message = "Sector creation failed.";
                return(Json(notification));
            }
        }
Пример #23
0
        /// <summary>
        /// ---------------------------BILL
        /// </summary>
        /// <param ></param>
        /// <param></param>
        ///
        private void cbbBuiding_Bill_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            if (comboBox.SelectedItem == null)
            {
                return;
            }
            SectorDTO sectorDTO = (SectorDTO)comboBox.SelectedValue;

            indexSectorIdSelected = sectorDTO.SectorId;
            SectorNameSelected    = sectorDTO.SectorName;
            GetListRoomBySectorId(indexSectorIdSelected);
            GetListBillViewByBuildingAndRoom(SectorNameSelected, indexRoomIdSelected);
        }
Пример #24
0
        public async Task <SectorDTO> UpdateSectorAsync(int id, SectorDTO sectorDTO)
        {
            var existedSector = await database.SectorRepository.GetEntityByIdAsync(id);

            var sector = mapper.Map <SectorDTO, Sector>(sectorDTO);

            sector.Id           = id;
            sector.CreateUserId = existedSector.CreateUserId;
            sector.CreateDate   = existedSector.CreateDate;
            sector.ModDate      = DateTime.Now;
            var  updatedSector    = database.SectorRepository.UpdateEntity(sector);
            var  updatedSectorDTO = mapper.Map <Sector, SectorDTO>(updatedSector);
            bool isSaved          = await database.SaveAsync();

            return((isSaved == true) ? updatedSectorDTO : null);
        }
Пример #25
0
        public async Task <SectorDTO> InsertSectorAsync(SectorDTO sectorDTO)
        {
            var sector         = mapper.Map <SectorDTO, Sector>(sectorDTO);
            var insertedSector = await database.SectorRepository.InsertEntityAsync(sector);


            bool isSaved = await database.SaveAsync();

            if (isSaved == false)
            {
                return(null);
            }
            else
            {
                return(mapper.Map <Sector, SectorDTO>(insertedSector));
            }
        }
        /// <summary>
        /// Saves a new Sector or updates an already existing Sector.
        /// </summary>
        /// <param name="Sector">Sector to be saved or updated.</param>
        /// <param name="SectorId">SectorId of the Sector creating or updating</param>
        /// <returns>SectorId</returns>
        public long SaveSector(SectorDTO sectorDTO, string userId)
        {
            long sectorId = 0;

            if (sectorDTO.SectorId == 0)
            {
                var sector = new Sector()
                {
                    Name      = sectorDTO.Name,
                    CreatedOn = DateTime.Now,
                    TimeStamp = DateTime.Now,
                    CreatedBy = userId,
                    Deleted   = false,
                };

                this.UnitOfWork.Get <Sector>().AddNew(sector);
                this.UnitOfWork.SaveChanges();
                sectorId = sector.SectorId;
                return(sectorId);
            }

            else
            {
                var result = this.UnitOfWork.Get <Sector>().AsQueryable()
                             .FirstOrDefault(e => e.SectorId == sectorDTO.SectorId);
                if (result != null)
                {
                    result.Name      = sectorDTO.Name;
                    result.UpdatedBy = userId;
                    result.TimeStamp = DateTime.Now;
                    result.Deleted   = sectorDTO.Deleted;
                    result.DeletedBy = sectorDTO.DeletedBy;
                    result.DeletedOn = sectorDTO.DeletedOn;

                    this.UnitOfWork.Get <Sector>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                return(sectorDTO.SectorId);
            }
            return(sectorId);
        }
Пример #27
0
        public async Task <ResponceModel> Update([FromRoute] int id, [FromBody] SectorDTO model)
        {
            var identifier = User.Claims.FirstOrDefault(p => p.Type == "id");

            if (identifier == null)
            {
                return(new ResponceModel(401, "FAILED", null, new string[] { "Yetkilendirme Hatası." }));
            }
            if (id == 0)
            {
                return(new ResponceModel(404, "ERROR", null, new string[] { "Güncellenecek veri bulunamadı." }));
            }
            try
            {
                var sector = await sectorService.Get(id);

                if (sector == null)
                {
                    return(new ResponceModel(404, "ERROR", null, new string[] { "Güncellenecek veri bulunamadı." }));
                }
                sector = model.Adapt <Sector>();
                sectorService.Update(sector);
                if (await sectorService.SaveChanges())
                {
                    return(new ResponceModel(200, "OK", sector, null));
                }
                else
                {
                    return(new ResponceModel(400, "ERROR", null, new string[] { "Veri güncellenirken sorun oluştu." }));
                }
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = sectorService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Veri güncellenirken sorun oluştu." }));
            }
        }
Пример #28
0
        public List <SectorDTO> getSectorByID(int pIdSector)
        {
            List <SectorDTO> oReturn = new List <SectorDTO>();
            SqlConnection    sqlCon  = DBLibrary.OpenConnection();

            try
            {
                SqlCommand sqlCmd = new SqlCommand();

                sqlCmd.Connection  = sqlCon;
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.CommandText = "sp_sector_consultar";
                sqlCmd.Parameters.AddWithValue("@IdSector", pIdSector);

                var oData = sqlCmd.ExecuteReader();

                while (oData.Read() == true)
                {
                    SectorDTO oSector = new SectorDTO();

                    oSector.idSector = int.Parse(oData["idSector"].ToString());
                    oSector.dsSector = oData["dsSector"].ToString();

                    oReturn.Add(oSector);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sqlCon.Close();
            }

            return(oReturn);
        }
Пример #29
0
        public bool AddTrain(SectorDTO sector)
        {
            try
            {
                _connect.Con.Open();

                MySqlCommand cmd = _connect.Con.CreateCommand();
                cmd.CommandText = "UPDATE sector SET idTram = '@idTram' WHERE Position = '@Position' AND idTrack = (SELECT idTrack FROM track WHERE TrackNumber = '@TrackNumber' AND idRemise = (SELECT idRemise FROM remise WHERE Name = '@DepotName'))";
                cmd.Parameters.AddWithValue("@idTram", sector.TramId);
                cmd.Parameters.AddWithValue("@Position", sector.SectorPosition);
                cmd.Parameters.AddWithValue("@TrackNumber", sector.TrackNumber);
                cmd.Parameters.AddWithValue("@DepotName", sector.DepotName);
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                _connect.Con.Close();
            }
            return(true);
        }
 public TramDTO GetTram(SectorDTO sector)
 {
     return(sector.Tram);
 }