示例#1
0
        /// <summary>
        /// Function Lock And Active ServicePack By Id ServicePack
        /// CreatedBy: HaiHM
        /// CreatedDate: 6/5/2019
        /// </summary>
        /// <param name="id">id of Service Pack</param>
        /// <returns>1= success, 0 fail </returns>
        public int ActiveAndLockServicePack(int id)
        {
            int result = 0;

            try
            {
                TblServicePack pack = GetServicePackById(id);
                if (pack != null)
                {
                    if (pack.IsActive == true)
                    {
                        pack.IsActive = false;
                    }
                    else
                    {
                        pack.IsActive = true;
                    }

                    db.Entry(pack).State = EntityState.Modified;
                    db.SaveChanges();
                    result = 1;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
            return(result);
        }
示例#2
0
        public IActionResult EditServicePack([FromBody] TblServicePack model)
        {
            if (model != null)
            {
                _servicePackRepository.EditServicePack(model);
            }

            return(BadRequest());
        }
示例#3
0
 /// <summary>
 /// Function get service pack by id
 /// CreatedBy: HaiHM
 /// CreatedDate: 7/5/2019
 /// </summary>
 /// <param name="id"></param>
 /// <returns>null or service pack has same id</returns>
 public TblServicePack GetServicePackById(int id)
 {
     try
     {
         TblServicePack obj = db.TblServicePack.Where(u => u.Id == id).FirstOrDefault();
         return(obj);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw ex;
     }
 }
示例#4
0
        /// <summary>
        /// Function Add ServicePack
        /// CreatedBy: HaiHM
        /// CreatedDate: 6/5/2019
        /// Not same [CodeServicePack], [NameServicePack]
        /// </summary>
        /// <param name="servicePack">obj</param>
        /// <returns>1= success, 0 fail, 2 same name or code </returns>
        public int AddServicePack(TblServicePack servicePack)
        {
            try
            {
                TblServicePack packCheck = db.TblServicePack.Where(sp => sp.IsDelete == false &&
                                                                   String.Compare(sp.CodeServicePack, servicePack.CodeServicePack, false) == 0 &&
                                                                   String.Compare(sp.CodeServicePack, servicePack.CodeServicePack, false) == 0).FirstOrDefault();

                if (packCheck == null)
                {
                    packCheck = new TblServicePack();
                    //packCheck.public int Id { get; set; }
                    packCheck.CodeServicePack = servicePack.CodeServicePack;
                    packCheck.NameServicePack = servicePack.NameServicePack;
                    packCheck.Description     = servicePack.Description;
                    packCheck.Avatar          = servicePack.Avatar;
                    packCheck.MaxUser         = servicePack.MaxUser;
                    packCheck.Price           = servicePack.Price;
                    packCheck.IsActive        = servicePack.IsActive;
                    packCheck.IsDelete        = servicePack.IsDelete;
                    packCheck.Discount        = servicePack.Discount;
                    packCheck.Hot             = servicePack.Hot;
                    packCheck.CreatedBy       = servicePack.CreatedBy;
                    packCheck.CreatedDate     = DateTime.Now;
                    packCheck.UpdatedBy       = servicePack.UpdatedBy;
                    packCheck.UpdatedDate     = DateTime.Now;

                    db.TblServicePack.Add(packCheck);
                    db.SaveChanges();
                    return(ServicePackConstant.AddServicePackSuccess);
                }
                else
                {
                    return(ServicePackConstant.AddServicePackFail);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
        }
示例#5
0
        /// <summary>
        /// Function Edit service pack
        /// CreatedBy: HaiHM
        /// CreatedDate: 7/5/2019
        /// </summary>
        /// <param name="servicePack"></param>
        /// <returns>1= success, 0 fail, 2 same name or code </returns>
        public int EditServicePack(TblServicePack servicePack)
        {
            try
            {
                TblServicePack packCheck = db.TblServicePack.Where(sp => sp.IsDelete == false && sp.Id == servicePack.Id).FirstOrDefault();

                if (packCheck != null)
                {
                    //packCheck = new TblServicePack();
                    //packCheck.public int Id { get; set; }
                    packCheck.CodeServicePack = servicePack.CodeServicePack;
                    packCheck.NameServicePack = servicePack.NameServicePack;
                    packCheck.Description     = servicePack.Description;
                    packCheck.Avatar          = servicePack.Avatar;
                    packCheck.MaxUser         = servicePack.MaxUser;
                    packCheck.Price           = servicePack.Price;
                    packCheck.IsActive        = servicePack.IsActive;
                    packCheck.IsDelete        = servicePack.IsDelete;
                    packCheck.Discount        = servicePack.Discount;
                    packCheck.Hot             = servicePack.Hot;
                    packCheck.UpdatedBy       = servicePack.UpdatedBy;
                    packCheck.UpdatedDate     = DateTime.Now;

                    db.Entry(packCheck).State = EntityState.Modified;
                    db.SaveChanges();
                    return(ServicePackConstant.EditServicePackSuccess);
                }
                else
                {
                    return(ServicePackConstant.EditServicePackFail);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
        }
示例#6
0
        /// <summary>
        /// CreatedBy: HaiHM
        /// CreatedDate: 7/5/2019
        /// Delete ServicePack By Id ServicePack
        /// </summary>
        /// <param name="id"></param>
        /// <returns>1= success, 0 fail </returns>
        public int DeleteServicePack(int id)
        {
            int result = ServicePackConstant.DeleteServicePackkFail;

            try
            {
                TblServicePack pack = GetServicePackById(id);
                if (pack != null)
                {
                    pack.IsDelete        = true;
                    pack.UpdatedDate     = DateTime.Now;
                    db.Entry(pack).State = EntityState.Modified;
                    db.SaveChanges();
                    result = ServicePackConstant.DeleteServicePackSuccess;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
            return(result);
        }