Пример #1
0
        public ActionResult CancelUserReferenceOrder(CancelOrderViewModel data)
        {
            try
            {
                using (MCContext ctx = new MCContext())
                {
                    var userReference = ctx.userReferences.FirstOrDefault(x => x.userId == data.userId);
                    if (userReference == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Referans bulunmamaktadır."));
                    }
                    var order = ctx.userReferenceOrders.FirstOrDefault(x => x.orderId == data.orderId);
                    if (order == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Sipariş bulunmamaktadır."));
                    }
                    if (order.activationDate < DateTime.Now)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Sipariş iptal edilemez."));
                    }
                    order.orderState = Enums.OrderState.canceled;
                    ctx.SaveChanges();

                    return(new HttpStatusCodeResult(HttpStatusCode.OK, "Sipariş iptal edilmiştir."));
                }
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
            }
        }
Пример #2
0
        public ActionResult DeleteCampaignRule(int campaignRuleId)
        {
            try
            {
                using (MCContext ctx = new MCContext())
                {
                    var rule = ctx.campaignRules.FirstOrDefault(x => x.id == campaignRuleId);
                    if (rule == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Böyle bir veri mevcut değildir."));
                    }

                    var enableToDelete = ctx.userReferenceOrders.FirstOrDefault(x => x.campaignRuleId == campaignRuleId && x.userReference.campaign.isActive && x.userReference.status != Enums.ReferenceStatus.passive) == null;
                    if (!enableToDelete)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Silmek istediğiniz kural aktif bir siparişe atandığı için silemezsiniz."));
                    }
                    ctx.campaignRules.Remove(rule);
                    ctx.SaveChanges();
                    return(Json(new { responseText = "Kural başarıyla silindi." }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(Json(new { message = "İşlem sırasında bir hata oluştu.", state = "error" }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #3
0
 public void ReferPatient(ReceptionModel receptionModels)
 {
     using (var context = new MCContext())
     {
         context.ReceptionModels.Add(receptionModels);
         context.SaveChanges();
     };
 }
 public void SaveAppointment(AppointmentModel appointmentModel)
 {
     using (var context = new MCContext())
     {
         context.AppointmentModels.Add(appointmentModel);
         context.SaveChanges();
     }
 }
Пример #5
0
 public void UpdateCategory(Category category)
 {
     using (var context = new MCContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #6
0
 public void SaveCategory(Category category)
 {
     using (var context = new MCContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
 public void SaveMedicine(AppointMedicineModel medicine)
 {
     using (var context = new MCContext())
     {
         context.AppointMedicineModels.Add(medicine);
         context.SaveChanges();
     }
 }
Пример #8
0
 public void UpdateProduct(Product product)
 {
     using (var context = new MCContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #9
0
 public void UpdateMedicine(MedicineModel model)
 {
     using (var context = new MCContext())
     {
         context.Entry(model).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #10
0
 public void SaveBill(BillModel model)
 {
     using (var context = new MCContext())
     {
         context.BillModels.Add(model);
         context.SaveChanges();
     }
 }
Пример #11
0
        public void AddMedicine(MedicineModel MedicineModel)
        {
            using (var context = new MCContext())
            {
                context.MedicineModels.Add(MedicineModel);

                context.SaveChanges();
            };
        }
 public override void Btn_Ok_Clicked()
 {
     using (var context = new MCContext()) {
         context.ProtocolOpDataTypes.Add(new ProtocolOpDataType {
             Description = text_description.Text
         });
         context.SaveChanges();
     }
     Close();
 }
Пример #13
0
        public void SaveProduct(Product product)
        {
            using (var context = new MCContext())
            {
                context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
Пример #14
0
        public ActionResult CreateUserReference(UserReferenceViewModel data)
        {
            try
            {
                if (string.IsNullOrEmpty(data.invitationCode))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Davet kodu boş olamaz."));
                }

                using (MCContext ctx = new MCContext())
                {
                    var invitation = ctx.userInvitations.FirstOrDefault(x => x.invitationCode.Equals(data.invitationCode) && x.invitationStatus == Enums.InvitationStatus.delivered);
                    if (invitation == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Davet bulunmamaktadır."));
                    }
                    var invitationCodeExists = ctx.userReferences.FirstOrDefault(x => x.userInvitationId == invitation.id) != null;
                    if (invitationCodeExists)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Davet kodu ile zaten referans kaydı vardır."));
                    }
                    if (data.userId == invitation.referenceUserId)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Kendine referans olamazsın."));
                    }
                    var activeCampaign = ctx.campaignRules.FirstOrDefault(x => x.campaign.isActive);
                    if (activeCampaign == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Aktif kampanya bulunmamaktadır."));
                    }
                    var userReference = ctx.userReferences.FirstOrDefault(x => x.userId == data.userId);
                    if (userReference != null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Bu kullanıcı zaten başka bir referansın daveti ile sisteme kayıt edilmiştir"));
                    }
                    ctx.userReferences.Add(new UserReference()
                    {
                        campaignId       = activeCampaign.id,
                        referenceUserId  = invitation.referenceUserId,
                        status           = Enums.ReferenceStatus.pending,
                        totalDiscount    = 0,
                        userId           = data.userId,
                        userInvitationId = invitation.id
                    });
                    ctx.SaveChanges();
                    return(new HttpStatusCodeResult(HttpStatusCode.OK, "Referans bağlantısı başarıyla kurulmuştur."));
                }
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
            }
        }
Пример #15
0
        public void DeleteProduct(int ID)
        {
            using (var context = new MCContext())
            {
                // context.Entry(product).State = System.Data.Entity.EntityState.Deleted; or

                var product = context.Products.Find(ID);
                context.Products.Remove(product);

                context.SaveChanges();
            }
        }
Пример #16
0
        public void DeleteCategory(int ID)
        {
            using (var context = new MCContext())
            {
                // context.Entry(category).State = System.Data.Entity.EntityState.Deleted; or

                var category = context.Categories.Find(ID);
                context.Categories.Remove(category);

                context.SaveChanges();
            }
        }
Пример #17
0
        public ActionResult UpdateCampaignRule(CampaignRuleViewModel model)
        {
            try
            {
                using (MCContext ctx = new MCContext())
                {
                    var rule = ctx.campaignRules.FirstOrDefault(x => x.id == model.campaignRuleId);
                    if (rule == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Böyle bir veri mevcut değildir."));
                    }
                    var campaignRule = ctx.campaignRules
                                       .FirstOrDefault(x => x.campaignId == model.campaignId &&
                                                       x.campaign.isActive &&
                                                       x.name.Equals(model.name, StringComparison.InvariantCulture) &&
                                                       x.id != model.campaignRuleId);
                    if (campaignRule != null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Kural sistemde zaten mevcut."));
                    }

                    var enableToUpdate = ctx.userReferenceOrders.FirstOrDefault(x => x.campaignRuleId == model.campaignRuleId && x.userReference.campaign.isActive && x.userReference.status != Enums.ReferenceStatus.passive) == null;
                    if (!enableToUpdate)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Güncellemek istediğiniz kural aktif bir siparişe atandığı için güncelleyemezsiniz."));
                    }
                    var indexExists = ctx.campaignRules
                                      .FirstOrDefault(x => x.index == model.index &&
                                                      x.campaign.isActive &&
                                                      x.campaignId == model.campaignId &&
                                                      x.id != model.campaignRuleId) != null;
                    if (indexExists)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Girdiğiniz sırada kural zaten mevcut. Lütfen farklı bir sıra numarası ile tekrar deneyiniz."));
                    }
                    rule.index         = model.index;
                    rule.name          = model.name;
                    rule.modifiedDate  = DateTime.Now;
                    rule.ruleType      = model.ruleType;
                    rule.description   = model.description;
                    rule.count         = model.count;
                    rule.atLeastPrice  = model.atLeastPrice;
                    rule.activationDay = model.activationDay;
                    ctx.SaveChanges();
                    return(Json(new { responseText = "Kural başarıyla güncellendi." }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
            }
        }
Пример #18
0
 public void SaveChanges()
 {
     try
     {
         _context.SaveChanges();
         _mcContext.SaveChanges();
         _maestrosContext.SaveChanges();
         _mooreveContext.SaveChanges();
         _sapContext.SaveChanges();
         _clientesContext.SaveChanges();
         _facturacionContext.SaveChanges();
     }
     catch (System.Exception e)
     {
         var msg = e.InnerException.Message;
     }
 }
Пример #19
0
 public static void InitDefaultCampaign()
 {
     try
     {
         if (WebConfigurationManager.AppSettings["EnableInitService"] != null && !Convert.ToBoolean(WebConfigurationManager.AppSettings["EnableInitService"]))
         {
             return;
         }
         using (MCContext ctx = new MCContext())
         {
             var isCampaignExists = ctx.campaigns.FirstOrDefault(x => x.isActive && x.rules.Count > 0) != null;
             if (!isCampaignExists)
             {
                 var newCampaign = ctx.campaigns.Add(new Campaign()
                 {
                     isActive = true,
                     name     = "Referans Üyelere Yüzdelik İndirim Kampanyası"
                 });
                 var percentages = new int[] { 10, 8, 6, 4, 2 };
                 var index       = 1;
                 foreach (var percentage in percentages)
                 {
                     ctx.campaignRules.Add(new CampaignRule()
                     {
                         atLeastPrice  = 0,
                         activationDay = 15,
                         count         = percentage,
                         description   = "Referans yolu ile üye olan kullanıcının " + index + ". alışverişinde yüzde " + percentage + " indirim.",
                         index         = index,
                         ruleType      = Enums.RuleTypes.percentage,
                         name          = "Yüzde " + percentage + " indirim",
                         campaign      = newCampaign
                     });
                     index++;
                 }
                 ctx.SaveChanges();
                 ActivityService.Log("InitDefaultCampaign çağırıldı.");
             }
         }
     }
     catch (Exception ex)
     {
         ActivityService.LogException(ex);
     }
 }
Пример #20
0
 public static void Log(string message, string requestIpAddress = null, int?userId = null, string userName = null)
 {
     try
     {
         using (MCContext ctx = new MCContext())
         {
             ctx.systemLogs.Add(new SystemLog()
             {
                 logMessage       = message,
                 requestIpAddress = requestIpAddress,
                 userId           = userId,
                 userName         = userName
             });
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         LogException(ex);
     }
 }
Пример #21
0
 public ActionResult AddCampaignRule(CampaignRuleViewModel model)
 {
     try
     {
         using (MCContext ctx = new MCContext())
         {
             var campaignRule = ctx.campaignRules
                                .FirstOrDefault(x => x.campaignId == model.campaignId &&
                                                x.campaign.isActive &&
                                                x.name.Equals(model.name, StringComparison.InvariantCulture));
             if (campaignRule != null)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Kural sistemde zaten mevcut."));
             }
             var indexExists = ctx.campaignRules.FirstOrDefault(x => x.index == model.index && x.campaign.isActive && x.campaignId == model.campaignId) != null;
             if (indexExists)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Girdiğiniz sırada kural zaten mevcut. Lütfen farklı bir sıra numarası ile tekrar deneyiniz."));
             }
             ctx.campaignRules.Add(new CampaignRule()
             {
                 activationDay = model.activationDay,
                 atLeastPrice  = model.atLeastPrice,
                 count         = model.count,
                 description   = model.description,
                 index         = model.index,
                 name          = model.name,
                 ruleType      = model.ruleType,
                 campaignId    = model.campaignId
             });
             ctx.SaveChanges();
             return(Json(new { responseText = "Kural başarıyla kaydedildi." }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         ActivityService.LogException(ex);
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
     }
 }
Пример #22
0
        private bool Add()
        {
            try {
                ProtocolOp Op = new ProtocolOp();

                int    CANidx = int.Parse(CANIdx.Text);
                string cancmd = CANcmd.Text.Trim();
                int    key    = Utils.MakeKey(cancmd, CANidx);

                var CAN = new ProtocolOpCAN()
                {
                    Cmd = CANcmd.Text,
                    Idx = int.Parse(CANIdx.Text)
                };
                var RS232 = new ProtocolOpRS232()
                {
                    Cmd = int.Parse(RS232cmd.Text),
                    Idx = int.Parse(RS232Idx.Text)
                };


                var DataType = combo_dataType.SelectedValue as ProtocolOpDataType;

                Op = new ProtocolOp()
                {
                    CAN       = CAN,
                    CmdName   = cmdName.Text,
                    CmdUIName = cmdUIName.Text,
                    DataType  = DataType,
                    RS232     = RS232
                };
                using (var context = new MCContext()) {
                    context.ProtocolOps.Add(Op);
                    context.SaveChanges();
                }
            } catch (Exception e) {
                return(Consts.FAIL);
            }
            return(Consts.PASS);
        }
Пример #23
0
        public static void LogException(Exception exception)
        {
            try
            {
                if (exception != null)
                {
                    StackFrame frame      = new StackFrame(1);
                    MethodBase methodBase = frame.GetMethod();

                    string methodName = methodBase.Name;
                    string className  = methodBase.DeclaringType.Name;

                    string    msg     = "";
                    int       exCount = 1;
                    Exception ex      = exception;
                    while (ex != null)
                    {
                        msg += exCount + "\n" + ex.Message + "\n" + ex.StackTrace + "\n\n";
                        ex   = ex.InnerException;
                        exCount++;
                    }

                    using (MCContext context = new MCContext())
                    {
                        ExceptionLog log = new ExceptionLog()
                        {
                            function         = methodName,
                            objectClass      = className,
                            exceptionMessage = msg,
                        };
                        context.exceptionLogs.Add(log);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex) { }
        }
Пример #24
0
        public ActionResult InviteUser(string email)
        {
            try
            {
                if (string.IsNullOrEmpty(email))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "E-posta alanı boş olmamalıdır."));
                }
                if (email.Equals(Session["UserName"].ToString(), StringComparison.InvariantCulture))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Kendinize davet gönderemezsiniz."));
                }

                var userId = Convert.ToInt32(Session["CurrentUserId"]);
                using (MCContext ctx = new MCContext())
                {
                    var invitations = ctx.userInvitations
                                      .Where(x => x.invitationStatus == Enums.InvitationStatus.delivered &&
                                             x.referenceUserId == userId);
                    var invitation = invitations.FirstOrDefault(x =>
                                                                x.mailAddress.Equals(email, StringComparison.InvariantCulture));
                    if (invitation != null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "E-posta adresini girmiş olduğunuz kişiye aktif davetiniz mevcuttur."));
                    }

                    if (WebConfigurationManager.AppSettings["UserInvitiationCount"] != null)
                    {
                        int limit = Convert.ToInt32(WebConfigurationManager.AppSettings["UserInvitiationCount"]);
                        if (invitations.Count() > limit)
                        {
                            return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Daha fazla davet isteği gönderemezsiniz."));
                        }
                    }
                    //todo: return bool IsEmailExists(string email)
                    if (true)
                    {
                        var code  = Extensions.RandomString(10);
                        var state = SendMail(email, code);
                        ctx.userInvitations.Add(new UserInvitation()
                        {
                            invitationStatus  = state,
                            referenceUserName = Session["UserName"].ToString(),
                            mailAddress       = email,
                            referenceUserId   = userId,
                            invitationCode    = code
                        });
                        ctx.SaveChanges();
                        return(Json(new { responseText = "Davet gönderildi." }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Kullanıcı sistemde zaten kayıtlıdır."));
                    }
                }
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
            }
        }
Пример #25
0
        public ActionResult CreateUserReferenceOrder(UserReferenceOrderViewModel data)
        {
            try
            {
                using (MCContext ctx = new MCContext())
                {
                    var userReference = ctx.userReferences
                                        .AsQueryable()
                                        .Include(x => x.campaign)
                                        .Include(x => x.campaign.rules)
                                        .Include(x => x.orders)
                                        .FirstOrDefault(x => x.userId == data.userId);
                    if (userReference == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Referans bulunmamaktadır."));
                    }
                    if (userReference.status != Enums.ReferenceStatus.passive)
                    {
                        var activeRule = new CampaignRule();
                        if (userReference.orders.Any())
                        {
                            var usedRules     = userReference.orders.Select(x => x.campaignRuleId).ToList();
                            var existingRules = ctx.campaignRules.Where(x => usedRules.Contains(x.id)).ToList();
                            activeRule = userReference.campaign.rules.Except(existingRules).OrderBy(x => x.index).FirstOrDefault();
                        }
                        else
                        {
                            activeRule = userReference.campaign.rules.OrderBy(x => x.index).FirstOrDefault();
                        }
                        if (activeRule == null)
                        {
                            return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Kampanya kuralı bulunmamaktadır."));
                        }
                        if (data.orderPrice < activeRule.atLeastPrice)
                        {
                            return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Sipariş tutarı en az harcama tutarının altındadır."));
                        }
                        var deservedDiscount = activeRule.ruleType == Enums.RuleTypes.amount ? activeRule.count : (data.orderPrice * activeRule.count) / 100;

                        if (ctx.userReferenceOrders.FirstOrDefault(x => x.orderId == data.orderId) == null)
                        {
                            ctx.userReferenceOrders.Add(new UserReferenceOrder()
                            {
                                activationDate   = data.orderDate.AddDays(activeRule.activationDay),
                                orderId          = data.orderId,
                                orderPrice       = data.orderPrice,
                                userReferenceId  = userReference.id,
                                orderState       = Enums.OrderState.paid,
                                deservedDiscount = deservedDiscount,
                                campaignRuleId   = activeRule.id
                            });
                            ctx.SaveChanges();
                            return(new HttpStatusCodeResult(HttpStatusCode.OK, "Sipariş kaydı oluşturulmuştur."));
                        }
                        else
                        {
                            return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Sipariş kaydı mevcuttur."));
                        }
                    }
                    else
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Referans bağlantısı aktif olmadığı için sisteme kayıt atılmamaktadır."));
                    }
                }
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
            }
        }
 public void SaveChanges()
 {
     _context.SaveChanges();
 }