Exemplo n.º 1
0
        public async Task <ActionResult <PointsLog> > PostPointsLog(PointsLog pointsLog)
        {
            _context.PointsLog.Add(pointsLog);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPointsLog", new { id = pointsLog.PhId }, pointsLog));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutPointsLog(Guid id, PointsLog pointsLog)
        {
            if (id != pointsLog.PhId)
            {
                return(BadRequest());
            }

            _context.Entry(pointsLog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PointsLogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public int CreatePointsLog(PointsLog log)
        {
            var    query    = GetAll();
            string nowDate  = DateTime.Now.ToString("yyyyMMdd");
            var    isExists = query.Where(o => o.UserId == log.UserId && o.AddTime == nowDate).FirstOrDefault();

            if (isExists == null)
            {
                return(InsertAndGetId(log));
            }
            else
            {
                return(0);
            }
        }
        public IHttpActionResult AddCategory()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form          = HttpContext.Current.Request.Form;
                    var subCategories = JsonConvert.DeserializeObject <List <SubCat> >(form.Get("subCategories")).ToList();

                    Category category = new Category();
                    category.Dept_Id = Convert.ToInt32(form.Get("deptId"));
                    category.Name    = form.Get("category");

                    if (subCategories.Count() > 0)
                    {
                        foreach (var subCat in subCategories)
                        {
                            SubCategory subCategory = new SubCategory();
                            PointsLog   pointslog   = new PointsLog();

                            subCategory.Name   = subCat.Name;
                            subCategory.Points = subCat.Points;

                            pointslog.Points   = subCat.Points;
                            pointslog.FromDate = DateTime.Now;

                            category.SubCategories.Add(subCategory);
                            subCategory.PointsLogs.Add(pointslog);
                        }
                    }
                    db.Categories.Add(category);
                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
            }
        }
        public IHttpActionResult EditCategory()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form          = HttpContext.Current.Request.Form;
                    int catId         = Convert.ToInt32(form.Get("catId"));
                    var subCategories = JsonConvert.DeserializeObject <List <NewSubCategory> >(form.Get("subCategories")).ToList();
                    var category      = db.Categories.Find(catId);

                    foreach (var subCategory in subCategories)
                    {
                        SubCategory subCat    = new SubCategory();
                        PointsLog   pointsLog = new PointsLog();

                        if (subCategory.SubCategoryId != null)
                        {
                            var subcat = db.SubCategories.Find(subCategory.SubCategoryId);
                            if (subcat.Points != subCategory.Points)
                            {
                                subcat.Points = subCategory.Points;
                                var subcatPointsLog = db.PointsLogs.Find(subCategory.PointsLogId);

                                if (subcatPointsLog != null)
                                {
                                    subcatPointsLog.ToDate          = MasterDataController.GetIndianTime(DateTime.Now);
                                    db.Entry(subcatPointsLog).State = System.Data.Entity.EntityState.Modified;
                                }
                                pointsLog.FromDate = MasterDataController.GetIndianTime(DateTime.Now);
                                pointsLog.Points   = subCategory.Points;
                                subcat.PointsLogs.Add(pointsLog);
                                db.Entry(subcat).State = System.Data.Entity.EntityState.Modified;
                            }
                            else
                            {
                                subcat.Name            = subCategory.Name;
                                subcat.Points          = subCategory.Points;
                                db.Entry(subcat).State = System.Data.Entity.EntityState.Modified;
                            }
                        }
                        else
                        {
                            subCat.Name   = subCategory.Name;
                            subCat.Points = subCategory.Points;

                            pointsLog.Points   = subCategory.Points;
                            pointsLog.FromDate = MasterDataController.GetIndianTime(DateTime.Now);

                            category.SubCategories.Add(subCat);
                            subCat.PointsLogs.Add(pointsLog);
                        }
                    }
                    db.SaveChanges();
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
            }
        }